****************************
** Footnote 14: Correlation between immigration and EU in the CHES (2014)
****************************

// Read in the CHES
use "2014_CHES_dataset_means-2.dta", replace
set more off

// Keep only UK data
tabulate cname
keep if cname=="uk"
tabulate party_name

// Keep only relevant parties
drop if party_name == "GREEN" | party_name == "PLAID" | party_name == "SNP"

// Correlation between EU issue and immigration issue. The two are coded in different directions.
cor eu_position immigrate_policy
cor eu_position immigrate_policy if party_name=="LIBDEM" | party_name == "UKIP"

// Read in the CHES, expert-level data
use "2014_CHES_dataset_expert-level.dta", replace
set more off

// Keep only UK data
tabulate cname
keep if cname=="uk"
tabulate party_name

// Keep only relevant parties
drop if party_name == "GREEN" | party_name == "PLAID" | party_name == "SNP"

// Correlation between EU issue and immigration issue. The two are coded in different directions.
cor eu_position immigrate_policy
cor eu_position immigrate_policy if party_name=="LIBDEM" | party_name == "UKIP"

****************************
** Footnote 14: Correlation between immigration and EU in the CHES (2017)
****************************

// Read in the CHES
use "CHES_means_2017.dta", replace
set more off

// Keep only UK data
tabulate country
decode country, gen(country_decoded)
keep if country_decoded=="uk"
tabulate party

// Keep only relevant parties
drop if party == "Greens" | party == "Plaid" | party == "SNP" | party == "SF" | party == "DUP"

// Correlation between EU issue and immigration issue. The two are coded in different directions.
cor position immigrate_policy
cor position immigrate_policy if party=="LibDem" | party == "UKIP"

// Read in the CHES, expert-level data
use "combined_experts_2017.dta", replace
set more off

// Keep only UK data
tabulate country
decode country, gen(country_decoded)
keep if country_decoded=="uk"
tabulate party

// Keep only relevant parties
drop if party == "Greens" | party == "Plaid" | party == "SNP" | party == "SF" | party == "DUP"

// Correlation between EU issue and immigration issue. The two are coded in different directions.
cor position immigrate_policy
cor position immigrate_policy if party=="LibDem" | party == "UKIP"

****************************
** Main analyses
****************************

// Read in the data
use Data_besparty.dta, clear

// Table 2
reg perc_ch ChangeInImmigEuPosit copartisan age male education_numeric i.wave if party!="LD" & party!="UKIP", vce(cluster id)
est store accuracy_eurevis
ologit partyPositionCertainty absChangeInImmigEuPosit copartisan age male education_numeric i.wave if party!="LD" & party!="UKIP", vce(cluster id)
est store certainty_eurevis

// Table 3
reg perc_ch ChangeInImmigEuPosit copartisan age male education_numeric i.wave if party!="Con" & party!="Lab", vce(cluster id)
est store accuracy_eurevis_ukip_ld
ologit partyPositionCertainty absChangeInImmigEuPosit copartisan age male education_numeric i.wave if party!="Con" & party!="Lab", vce(cluster id)
est store certainty_eurevis_ukip_ld

// Substantive effect sizes for updating model (divided parties)
reg perc_ch ChangeInImmigEuPosit copartisan age male education_numeric i.wave if party!="LD" & party!="UKIP", vce(cluster id)
summarize ChangeInImmigEuPosit if party!="LD" & party!="UKIP"
margins, at(ChangeInImmigEuPosit=(-0.082 0.054)) atmeans
summarize perc_ch if party!="LD" & party!="UKIP"

// Substantive effect sizes for certainty model (divided parties) - Figure 1
ologit partyPositionCertainty absChangeInImmigEuPosit copartisan age male education_numeric i.wave if party!="LD" & party!="UKIP", vce(cluster id)
summarize absChangeInImmigEuPosit if party!="LD" & party!="UKIP", detail
margins, at(absChangeInImmigEuPosit=(.0011905(0.001).0973354)) atmeans predict(outcome(3))
marginsplot, recast(line) recastci(rarea) xtitle("Absolute Change in Policy Position") ytitle("Pr(Very Certain)") title("")
graph export plot_certainty_divided_vc.pdf, replace
margins, at(absChangeInImmigEuPosit=(.0011905(0.001).0973354)) atmeans predict(outcome(1))
marginsplot, recast(line) recastci(rarea) xtitle("Absolute Change in Policy Position") ytitle("Pr(Not At All Certain)") title("")
graph export plot_certainty_divided_nc.pdf, replace

margins, predict(outcome(3)) at(absChangeInImmigEuPosit=(.0480859  .0900285)) atmeans
margins, predict(outcome(3)) at(absChangeInImmigEuPosit=(.0480859  .0900285)) atmeans pwcompare 

margins, predict(outcome(1)) at(absChangeInImmigEuPosit=(.0480859  .0900285)) atmeans
margins, predict(outcome(1)) at(absChangeInImmigEuPosit=(.0480859  .0900285)) atmeans pwcompare 

// Substantive effect sizes for updating model (united parties)
reg perc_ch ChangeInImmigEuPosit copartisan age male education_numeric i.wave if party!="Con" & party!="Lab", vce(cluster id)
summarize ChangeInImmigEuPosit if party=="UKIP" | party=="LD"
margins, at(ChangeInImmigEuPosit=(-0.252 0.299)) atmeans
summarize perc_ch if party=="UKIP" | party=="LD"

// Substantive effect sizes for certainty model (united parties) - Figure 2
ologit partyPositionCertainty absChangeInImmigEuPosit copartisan age male education_numeric i.wave if party!="Con" & party!="Lab", vce(cluster id)
summarize absChangeInImmigEuPosit if party!="Con" & party!="Lab", detail
margins, at(absChangeInImmigEuPosit=(.0273973(0.01).5595238)) atmeans predict(outcome(3))
marginsplot, recast(line) recastci(rarea) xtitle("Absolute Change in Policy Position") ytitle("Pr(Very Certain)") title("")
graph export plot_certainty_united_vc.pdf, replace
margins, at(absChangeInImmigEuPosit=(.0273973(0.01).5595238)) atmeans predict(outcome(1))
marginsplot, recast(line) recastci(rarea) xtitle("Absolute Change in Policy Position") ytitle("Pr(Not At All Certain)") title("")
graph export plot_certainty_united_nc.pdf, replace

margins, predict(outcome(3)) at(absChangeInImmigEuPosit=(.091 .417)) atmeans
margins, predict(outcome(3)) at(absChangeInImmigEuPosit=(.091 .417)) atmeans pwcompare 

margins, predict(outcome(1)) at(absChangeInImmigEuPosit=(.091 .417)) atmeans
margins, predict(outcome(1)) at(absChangeInImmigEuPosit=(.091 .417)) atmeans pwcompare 
